/* 
    file:   ui_image.c
 */
/* ------------------------------------------------------------------------- */
#include "ui_image.h"
#include "ui_draw_img.h"
#include "lvgl.h"
#include "stdio.h"



uint8_t ui_image_sc(struct ui_obj * obj, uint8_t sign, void * param)
{
    // int sx = 0;
    // int sy = 0;
    point realpoint;
    struct ui_core * pcore = NULL;
   
    ui_getlct(obj,&realpoint);
    // sx = obj->area.x2-obj->area.x1;
    // sy = obj->area.y2-obj->area.y1;

    if(param)
    {
        pcore = (struct ui_core *)param;
        if(sign == ui_signal_init)
        {
            //ui_draw_img_a(pcore->pscr,obj,0,0);
            ui_draw_img_b(pcore->pscr, 0,*(lv_img_dsc_t **)(obj->objdat),&realpoint,0);
        }
    }
    return 0;
}

struct ui_obj * ui_newimage(struct ui_obj * ppar)
{
    struct ui_obj * pnewobj = NULL;
    pnewobj = ui_newobj(ppar);

    pnewobj->signal_cb = ui_image_sc;

    pnewobj->objdat = ui_malloc(sizeof(void *));

    *(void **)(pnewobj->objdat) = NULL;

    pnewobj->area.x1 = 0;
    pnewobj->area.y1 = 0;
    pnewobj->area.x2 = 0;
    pnewobj->area.y2 = 0;

    return pnewobj;
}

void ui_image_set_pos(struct ui_obj * pobj,uint32_t px,uint32_t py)
{
    uint32_t sx,sy;
    sx = pobj->area.x2-pobj->area.x1;
    sy = pobj->area.y2-pobj->area.y1;
    pobj->area.x1 = px;
    pobj->area.y1 = py;
    pobj->area.x2 = px + sx;
    pobj->area.y2 = py + sy;
}   
void ui_imgage_set_img(struct ui_obj * pobj,const void * pimg)
{
    lv_img_dsc_t * pimgt;
    *(void **)(pobj->objdat) = (void *)pimg;
    pimgt = (lv_img_dsc_t *)pimg;
    pobj->area.x2 = pobj->area.x1 + pimgt->header.w-1;
    pobj->area.y2 = pobj->area.y1 + pimgt->header.h-1;
}
